<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <button id="herf">herf</button>
  <button id="open">window.open</button>

  
  <script>
    const oHBtn = document.getElementById('herf')
    const oPenBtn = document.getElementById('open')

    oHBtn.addEventListener('click', () => {
      console.log(1)
      window.location.href = 'www.baidu.com'
    }, false)

    oPenBtn.addEventListener('click', () => {
      console.log(2)
      window.open('https://developer.mozilla.org/zh-CN/docs/Web/API/Window/open')

    }, false)

    oPenBtn.click()
    oHBtn.click()
  </script>
</body>
</html>